package com.jxwifi.cloud.quickclean.orderdetails;

import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.StrictMode;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.basicactivity.BasicActivity;
import com.idroid.widget.CircleImageView;
import com.idroid.widget.LoadDialog;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.app.AccountMgr;
import com.jxwifi.cloud.quickclean.app.ClientBasicActivity;
import com.jxwifi.cloud.quickclean.app.MyMessageReceiver;
import com.jxwifi.cloud.quickclean.app.PasswordLogin;
import com.jxwifi.cloud.quickclean.app.StateUtils;
import com.jxwifi.cloud.quickclean.bean.CardRollBean;
import com.jxwifi.cloud.quickclean.pay.PayResult;
import com.jxwifi.cloud.quickclean.utils.ToastUtils;
import com.umeng.analytics.MobclickAgent;
import com.view.SuperSwipeRefreshLayout;

import org.simple.eventbus.Subscriber;

import java.net.URL;
import java.net.URLConnection;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OrderDetailsActivity extends ClientBasicActivity implements OrderDetailsView,OrderStatusListener{

    private String TAG = this.getClass().getSimpleName();
    @Bind(R.id.rel_img_back_pressed)
    RelativeLayout mRelImgBackPressed;
    @Bind(R.id.rel_img_dian)
    RelativeLayout mRelImgDian;
    @Bind(R.id.tv_titlebar_text)
    TextView mTvTitlebarText;
    @Bind(R.id.sv_order_details)
    ScrollView mSvOrderDetails;


    @Bind(R.id.lin_work_bench_time_layout)
    LinearLayout mLinWorkBenchTimeLayout;
    @Bind(R.id.tv_workbench_use_time_hours)
    TextView mTvWorkbenchUseTimeHours;
    @Bind(R.id.tv_workbench_use_time_mines)
    TextView mTvWorkbenchUseTimeMines;
    @Bind(R.id.tv_workbench_income_text)
    TextView mTvWorkbenchIncomeText;

    //保洁员布局
    @Bind(R.id.rel_order_details_cleaning)
    RelativeLayout mRelOrderDetailsCleaning;
    @Bind(R.id.img_order_details_photo)
    CircleImageView mImgOrderDetailsPhoto;
    @Bind(R.id.tv_cleaning_name)
    TextView mTvCleaningName;
    @Bind(R.id.rb_order_details_list)
    RatingBar mRbOrderDetailsList;
    @Bind(R.id.tv_cleaning_location)
    TextView mTvCleaningLocation;

    @Bind(R.id.tv_in_the_dispatch)
    TextView mTvInTheDispatch;
    @Bind(R.id.tv_payment_of_bills)
    TextView mTvPaymentOfBills;
    @Bind(R.id.tv_having_set_out)
    TextView mTvHavingSetOut;
    @Bind(R.id.tv_details_arrived)
    TextView mTvDetailsArrived;
    @Bind(R.id.tv_beginning)
    TextView mTvBeginning;
    @Bind(R.id.tv_completed)
    TextView mTvCompleted;

    @Bind(R.id.img_in_the_dispatch)
    ImageView mImgInTheDispatch;
    @Bind(R.id.img_payment_of_bills)
    ImageView mImgPaymentOfBills;
    @Bind(R.id.img_having_set_out)
    ImageView mImgHavingSetOut;
    @Bind(R.id.img_details_arrived)
    ImageView mImgDetailsArrived;
    @Bind(R.id.img_beginning)
    ImageView mImgBeginning;
    @Bind(R.id.img_completed)
    ImageView mImgCompleted;

    @Bind(R.id.rel_order_details_payment)
    RelativeLayout mRelOrderDetailsPayment;
    @Bind(R.id.tv_order_details_tail_money)
    TextView mTvOrderDetailsTailMoney;


    @Bind(R.id.rel_order_details_center)
    RelativeLayout mRelOrderDetailsCenter;
    @Bind(R.id.tv_order_details_deposit)
    TextView mTvOrderDetailsDeposit;
    @Bind(R.id.tv_order_details_cleaner)
    TextView mTvOrderDetailsCleaner;
    @Bind(R.id.tv_order_details_service_times)
    TextView mTvOrderDetailsServiceTimes;
    @Bind(R.id.tv_order_details_address_content)
    TextView mTvOrderDetailsAddressContent;
    @Bind(R.id.tv_order_details_phone)
    TextView mTvOrderDetailsPhone;
    @Bind(R.id.tv_order_details_number)
    TextView mTvOrderDetailsNumber;
    @Bind(R.id.tv_order_details_size)
    TextView mTvOrderDetailsSize;
    @Bind(R.id.tv_order_details_explain_return)
    TextView mTvOrderDetailsExplainReturn;
    @Bind(R.id.tv_order_details_explain)
    TextView mTvOrderDetailsExplain;
    @Bind(R.id.tv_order_details_cleaning_phone)
    TextView mTvOrderDetailsCleaningPhone;


    @Bind(R.id.rel_order_details_starts)
    RelativeLayout mRelOrderDetailsStarts;
    @Bind(R.id.tv_order_details_process)
    TextView mTvOrderDetailsProcess;
    @Bind(R.id.tv_order_details_starts_time)
    TextView mTvOrderDetailsStartsTime;
    @Bind(R.id.tv_cleaning_reward)
    TextView mTvCleaningReward;
    @Bind(R.id.tv_collection)
    TextView tv_collection;

    @Bind(R.id.srl_my_order_list)
    SuperSwipeRefreshLayout mSrlMyOrderList;
    @Bind(R.id.tv_change_time)
    TextView tv_change_time;
    @Bind(R.id.tv_order_details_cleaner_details)
    TextView tv_order_details_cleaner_details;


    private OrderDetailsPresenter mPresenter;
    private String orderCode;//订单编码

    public LoadDialog mLoadDialog;//加载动画
    private boolean mIsFinished=true;

    private String mWXPayCode;//微信支付接口返回的code
    private MyMessageReceiver myMessageReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_details);
        ButterKnife.bind(this);
        openEventBus();
        mLoadDialog = new LoadDialog(mBaseContext, "");
        //mLoadDialog.setCancelable(false);
        mLoadDialog.show();
        orderCode = getIntent().getStringExtra("order_code");
        mPresenter = new OrderDetailsPresenter(mBaseContext, this);
        //Log.i(TAG,"onCreate");
        tv_change_time.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
        tv_change_time.getPaint().setAntiAlias(true);//抗锯齿
        tv_order_details_cleaner_details.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
        tv_order_details_cleaner_details.getPaint().setAntiAlias(true);//抗锯齿
        mTvOrderDetailsExplain.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
        mTvOrderDetailsExplain.getPaint().setAntiAlias(true);//抗锯齿

        //解决getNetTime() android.os.NetworkOnMainThreadException
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        //注册广播 ------接口回调不能使用静态注册,只能动态注册
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.alibaba.push2.action.NOTIFICATION_OPENED");
        intentFilter.addAction("com.alibaba.push2.action.NOTIFICATION_REMOVED");
        intentFilter.addAction("com.alibaba.sdk.android.push.RECEIVE");
        myMessageReceiver = new MyMessageReceiver();
        registerReceiver(myMessageReceiver, intentFilter);
        myMessageReceiver.SetOrderStatusListenner(this);

    }

    @OnClick({R.id.rel_img_back_pressed, R.id.rel_img_dian, R.id.tv_order_details_cleaning_phone, R.id.tv_cleaning_location, R.id.tv_order_details_tail_money_button
            , R.id.rel_order_details_starts,R.id.tv_order_details_explain,R.id.tv_order_details_cleaner_details,R.id.tv_cleaning_reward,R.id.tv_change_time,R.id.tv_collection})
    void clickCK(View v) {
        Intent intent=new Intent();
        switch (v.getId()) {
            case R.id.rel_img_back_pressed:
                onBackPressed();
                break;
            case R.id.rel_img_dian:
                mPresenter.DialogShow();
                break;
            //保洁员电话
            case R.id.tv_order_details_cleaning_phone:
                mPresenter.CleaningTell();
                MobclickAgent.onEvent(mBaseContext, "tv_order_details_cleaning_phone");
                break;
            //保洁员位置
            case R.id.tv_cleaning_location:
                mPresenter.CleamingLocation();
                MobclickAgent.onEvent(mBaseContext, "tv_cleaning_location");
                break;
            //支付尾款按钮
            case R.id.tv_order_details_tail_money_button:
                mPresenter.getPayOrder();
                MobclickAgent.onEvent(mBaseContext, "tv_order_details_tail_money_button");
                break;
            //订单状态弹框显示数据按钮
            case R.id.rel_order_details_starts:
                mPresenter.OrderStart();
                break;
                //费用说明
            case R.id.tv_order_details_explain:
                mPresenter.priceDetail();
                MobclickAgent.onEvent(mBaseContext, "tv_order_details_explain");
                break;
                //保洁详情
            case R.id.tv_order_details_cleaner_details:
                mPresenter.ServiceDetails();
                break;
                //小费
            case R.id.tv_cleaning_reward:
                mPresenter.getRewardData();
                MobclickAgent.onEvent(mBaseContext, "tv_cleaning_reward");
                break;
            case R.id.tv_change_time:
                mPresenter.TimeChoice();
                //MobclickAgent.onEvent(mBaseContext, "tv_cleaning_reward");
                break;
            case R.id.tv_collection:
                //Log.i(TAG,"isCollected = "+mPresenter.mOrderDetails.getCleanerInfo().isCollected());
                if(mPresenter.mOrderDetails.getCleanerInfo().isCollected()){
                    mPresenter.CancelCollectionCleaner();
                }else{
                    mPresenter.collectionCleaner();
                }

                //MobclickAgent.onEvent(mBaseContext, "tv_cleaning_reward");
            break;
        }
    }

    @Subscriber(tag = "e-WXPayResult")
    private void getWXCondItion(PayResult mBean) {
        mIsFinished=false;
        Toast toast = Toast.makeText(mBaseContext, "支付成功", Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 3000);
        mLoadDialog.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mPresenter.getData();
                mLoadDialog.dismiss();
                Log.i(TAG,"getWXCondItion ==> dismiss");
            }
        }, 1000);
    }

    @Override
    public void OnPayReward(String rewardCode, String PayType, String PayPrice) {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.onPayReward(rewardCode,PayType,PayPrice);
        }
    }

    @Override
    public TextView getCleaningReward() {
        return mTvCleaningReward;
    }

    @Override
    public TextView getCollection() {
        return tv_collection;
    }

    @Override
    public void getWXPayCode(String mOutTradNo) {
        mWXPayCode=mOutTradNo;
    }

    @Override
    public void onShowToster() {
        Toast toast = Toast.makeText(mBaseContext, "正在努力派单中...", Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 3000);
    }

    @Override
    public SuperSwipeRefreshLayout getSwip() {
        return mSrlMyOrderList;
    }

    @Override
    public void onIsFinished(boolean finished) {
        mIsFinished=finished;
    }

    @Override
    public TextView getCleaningPhone() {
        return mTvOrderDetailsCleaningPhone;
    }

    @Override
    public TextView getChangeTime() {
        return tv_change_time;
    }

    @Override
    public TextView getCleaningLocation() {
        return mTvCleaningLocation;
    }

    @Override
    public ScrollView getSvOrderDetails() {
        return mSvOrderDetails;
    }

    @Override
    public TextView getTitlebarText() {
        return mTvTitlebarText;
    }

    @Override
    public TextView getExplain() {
        return mTvOrderDetailsExplain;
    }

    @Override
    public TextView getExplainReturn() {
        return mTvOrderDetailsExplainReturn;
    }

    @Override
    public TextView getTailMoney() {
        return mTvOrderDetailsTailMoney;
    }

    @Override
    public TextView getIncomeText() {
        return mTvWorkbenchIncomeText;
    }

    @Override
    public TextView getTimeMines() {
        return mTvWorkbenchUseTimeMines;
    }

    @Override
    public TextView getTimeHours() {
        return mTvWorkbenchUseTimeHours;
    }

    @Override
    public ImageView getImgCompleted() {
        return mImgCompleted;
    }

    @Override
    public TextView getCompleted() {
        return mTvCompleted;
    }

    @Override
    public ImageView getImgBeginning() {
        return mImgBeginning;
    }

    @Override
    public TextView getBeginning() {
        return mTvBeginning;
    }

    @Override
    public ImageView getImgDetailsArrived() {
        return mImgDetailsArrived;
    }

    @Override
    public TextView getDetailsArrived() {
        return mTvDetailsArrived;
    }

    @Override
    public ImageView getImgHavingSetOut() {
        return mImgHavingSetOut;
    }

    @Override
    public TextView getHavingSetOut() {
        return mTvHavingSetOut;
    }

    @Override
    public ImageView getImgPaymentOfBills() {
        return mImgPaymentOfBills;
    }

    @Override
    public TextView getPaymentOfBills() {
        return mTvPaymentOfBills;
    }

    @Override
    public TextView getInTheDispatch() {
        return mTvInTheDispatch;
    }

    @Override
    public ImageView getImgInTheDispatch() {
        return mImgInTheDispatch;
    }

    @Override
    public RelativeLayout getRelImgDian() {
        return mRelImgDian;
    }

    @Override
    public String getOrderCode() {
        return orderCode;
    }

    @Override
    public LinearLayout getWorkBenchTime() {
        return mLinWorkBenchTimeLayout;
    }

    @Override
    public RelativeLayout getCleaning() {
        return mRelOrderDetailsCleaning;
    }

    @Override
    public CircleImageView getCircle() {
        return mImgOrderDetailsPhoto;
    }

    @Override
    public TextView getCleaningName() {
        return mTvCleaningName;
    }

    @Override
    public RatingBar getRatingBar() {
        return mRbOrderDetailsList;
    }

    @Override
    public RelativeLayout getPayment() {
        return mRelOrderDetailsPayment;
    }

    @Override
    public RelativeLayout getDetailsCenter() {
        return mRelOrderDetailsCenter;
    }

    @Override
    public RelativeLayout getDetailsStarts() {
        return mRelOrderDetailsStarts;
    }

    @Override
    public TextView getDetailsProcess() {
        return mTvOrderDetailsProcess;
    }

    @Override
    public TextView getStartsTime() {
        return mTvOrderDetailsStartsTime;
    }

    @Override
    public TextView getDetailsDeposit() {
        return mTvOrderDetailsDeposit;
    }

    @Override
    public TextView getDetailsCleaner() {
        return mTvOrderDetailsCleaner;
    }

    @Override
    public TextView getServiceTimes() {
        return mTvOrderDetailsServiceTimes;
    }

    @Override
    public TextView getAddressContent() {
        return mTvOrderDetailsAddressContent;
    }

    @Override
    public TextView getDetailsPhone() {
        return mTvOrderDetailsPhone;
    }

    @Override
    public TextView getDetailsNumber() {
        return mTvOrderDetailsNumber;
    }

    @Override
    public TextView getDetailsSize() {
        return mTvOrderDetailsSize;
    }

    @Override
    public void onFailure(int errorCode, String msg) {
        Log.i(TAG,"onFailure ==> errorCode = "+errorCode+" msg = "+msg);
        Toast toast = Toast.makeText(mBaseContext, msg, Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 3000);
    }

    @Override
    public void onSuccess(int errorCode, String msg) {
        Toast toast = Toast.makeText(mBaseContext, msg, Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 1000);
    }

    @Override
    public void onByNoMoney() {
        mIsFinished=false;
        mLoadDialog.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Toast toast = Toast.makeText(mBaseContext, "支付成功", Toast.LENGTH_SHORT);
                ToastUtils.showMyToast(toast, 3000);
                Log.i(TAG,"onByNoMoney ==> getData()");
                mPresenter.getData();
                mLoadDialog.dismiss();
                Log.i(TAG,"onByNoMoney ==> dismiss");
            }
        }, 1000);
    }

    @Subscriber(tag = "e-PayResult")
    private void getCondItion(PayResult mBean) {
        mIsFinished=false;
        Toast toast = Toast.makeText(mBaseContext, "支付成功", Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast, 3000);
        mLoadDialog.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mPresenter.getData();
                mLoadDialog.dismiss();
                Log.i(TAG,"getCondItion ==> dismiss");
            }
        }, 1000);
    }

    @Subscriber(tag = "e-CardRoll")
    private void getCardRoll(CardRollBean mRollBean) {
        mPresenter.CarRollData(mRollBean);
    }

    @Override
    public void onData() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            Log.i(TAG,"onData ==> getData()");
            mPresenter.getData();
        }
    }

    @Override
    public void oninitgettime() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.initgettime();
        }
    }

    @Override
    public void onpriceDetail() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.priceDetail();
        }
    }

    @Override
    public void onServiceDetails() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.ServiceDetails();
        }
    }

    @Override
    public void onOrderCancle(String cancelReason) {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.getOrderCancle(cancelReason);
        }
    }

    @Override
    public void oninittell() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.inittell();
        }
    }

    @Override
    public void OnonPaySurplus(String PayType) {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.onPaySurplus(PayType);
        }
    }

    @Override
    public void onByCoupon() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.ByCoupon();
        }
    }

    @Override
    public void NoMoney() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.ByNoMoney();
        }
    }

    @Override
    public void onCoupons() {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.getCoupons();
        }
    }

    @Override
    public void onEvaluateData(int grade, String title) {
        PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
        if (PasswordLogin.mIsLogin) {
            mPresenter.EvaluateData(grade,title);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mIsFinished){
            mLoadDialog.show();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Log.i(TAG,"onResume ==> getData()");
                    mPresenter.getData();
                    mLoadDialog.dismiss();
                    Log.i(TAG,"onResume ==> dismiss");
                }
            }, 1000);

        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        mPresenter.onTimeCancel();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mPresenter.onTimeCancel();
    }

    /**
     * 获取网络时间
     */
    private void getNetTime(String serviceTime) {
        URL url = null;//取得资源对象
        //legalDate = this.getResources().getString(R.string.legalDate);
        try {
            url = new URL("http://www.baidu.com");
            //url = new URL("http://www.ntsc.ac.cn");//中国科学院国家授时中心
            //url = new URL("http://www.bjtime.cn");
            URLConnection uc = url.openConnection();//生成连接对象
            uc.connect(); //发出连接
            long ld = uc.getDate(); //取得网站日期时间
            Log.i(TAG,"getNetTime() ==> ld ="+ld);
            DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(ld);
            String date = formatter.format(calendar.getTime());
            Log.i(TAG, "getNetTime() ==> date = "+date+" 服务时间 = "+serviceTime);

            Date netDate = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(date);
            Date serviceDate = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(serviceTime);

            int min = (int)(serviceDate.getTime() - netDate.getTime())/60000;
            //Log.i(TAG,"getNetTime ==> 距离服务时间还差 "+min+"分钟"+" (int)(serviceDate.getTime() - netDate.getTime()) = "+(int)(serviceDate.getTime() - netDate.getTime())+" 服务器超时时间 = "+AccountMgr.getOrderTimeOut(mBaseContext));
            //当距离服务时间1小时，提示客户
            if (min <= AccountMgr.getOrderTimeOut(mBaseContext)){
                mPresenter.reminderDialog();
            }
            /*runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    //Toast.makeText(VideoPlayActity.this, "当前网络时间为: \n" + date, Toast.LENGTH_SHORT).show();

                }
            });*/
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    public void getServiceTime(final String serviceTime) {
        Log.i(TAG, "getServiceTime() ==> serviceTime = "+serviceTime);
        //请求网络资源是耗时操作。放到子线程中进行
        new Thread(new Runnable() {
            @Override
            public void run() {
                Looper.prepare();//增加部分
                getNetTime(serviceTime);
                Looper.loop();
            }
        }).start();

    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            onBackPressed();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void getOrderStatus(String content) {
        Log.i(TAG,"MyMessageReceiver 收到阿里云推送回调信息："+content);
        mLoadDialog.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mPresenter.getData();
                mLoadDialog.dismiss();
                Log.i(TAG,"getOrderStatus ==> dismiss");
            }
        }, 1000);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(myMessageReceiver);
    }


    /*public interface OrderStatusListener {
        //接收阿里云推送内容
        void getOrderStatus(String content);
    }*/
}
